home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-06-03 | 8.8 KB | 286 lines | [TEXT/CWIE] |
- //========================================================================================
- //
- // File: Commands.cpp
- // Release Version: $ ODF 1 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "Form.hpp"
-
- #ifndef COMMANDS_H
- #include "Commands.h"
- #endif
-
- #ifndef PART_H
- #include "Part.h"
- #endif
-
- #ifndef CONTENT_H
- #include "Content.h"
- #endif
-
- // ----- Framework Includes -----
-
- #ifndef FWPRESEN_H
- #include "FWPresen.h"
- #endif
-
- // ----- OpenDoc Includes -----
-
- #ifndef SOM_Module_OpenDoc_Commands_defined
- #include <CmdDefs.xh>
- #endif
-
- //========================================================================================
- // RunTime Info
- //========================================================================================
-
- #ifdef FW_BUILD_MAC
- #pragma segment Form
- #endif
-
- FW_DEFINE_AUTO(CFormEditCommand)
- FW_DEFINE_AUTO(CFormDropCommand)
- FW_DEFINE_AUTO(CFormDragCommand)
-
- //========================================================================================
- // CFormEditCommand
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CFormEditCommand constructor
- //----------------------------------------------------------------------------------------
-
- CFormEditCommand::CFormEditCommand(Environment* ev,
- ODCommandID id,
- CFormContent* itsContent,
- FW_CFrame* frame) :
- FW_CClipboardCommand(ev, id, frame, FW_kCanUndo),
- fFormContent(itsContent)
- {
- switch (id)
- {
- case kODCommandCut:
- SetMenuStringsFromResource(ev, kFormUndoStrings, kUndoCutTextMsg, kRedoCutTextMsg);
- break;
- case kODCommandClear:
- SetMenuStringsFromResource(ev, kFormUndoStrings, kUndoClearTextMsg, kRedoClearTextMsg);
- break;
- case kODCommandPaste:
- SetMenuStringsFromResource(ev, kFormUndoStrings, kUndoPasteTextMsg, kRedoPasteTextMsg);
- break;
- }
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CFormEditCommand destructor
- //----------------------------------------------------------------------------------------
-
- CFormEditCommand::~CFormEditCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CFormEditCommand::SaveUndoState
- //----------------------------------------------------------------------------------------
-
- void CFormEditCommand::SaveUndoState(Environment *ev)
- {
- fSavedTextData = fFormContent->GetTextData();
- }
-
- //----------------------------------------------------------------------------------------
- // CFormEditCommand::UndoIt
- //----------------------------------------------------------------------------------------
-
- void CFormEditCommand::UndoIt(Environment* ev)
- {
- FW_CClipboardCommand::UndoIt(ev); // call inherited
-
- switch (GetCommandID(ev))
- {
- case kODCommandCut:
- case kODCommandClear:
- this->RestoreSelection(ev);
- break;
-
- case kODCommandPaste:
- this->SwapSelection(ev);
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CFormEditCommand::RedoIt
- //----------------------------------------------------------------------------------------
-
- void CFormEditCommand::RedoIt(Environment *ev)
- {
- FW_CClipboardCommand::RedoIt(ev); // call inherited
-
- switch (GetCommandID(ev))
- {
- case kODCommandCut:
- case kODCommandClear:
- this->RemoveSelection(ev);
- break;
-
- case kODCommandPaste:
- this->SwapSelection(ev);
- break;
- }
- }
-
- //----------------------------------------------------------------------------------------
- // CFormEditCommand::RemoveSelection
- //----------------------------------------------------------------------------------------
-
- void CFormEditCommand::RemoveSelection(Environment* ev)
- {
- fFormContent->ClearTextData(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CFormEditCommand::RestoreSelection
- //----------------------------------------------------------------------------------------
-
- void CFormEditCommand::RestoreSelection(Environment* ev)
- {
- fFormContent->SetTextData(ev, fSavedTextData);
- }
-
- //----------------------------------------------------------------------------------------
- // CFormEditCommand::SwapSelection
- //----------------------------------------------------------------------------------------
-
- void CFormEditCommand::SwapSelection(Environment* ev)
- {
- FW_CString255 textData = fFormContent->GetTextData();
- fFormContent->SetTextData(ev, fSavedTextData);
- fSavedTextData = textData;
- }
-
- //========================================================================================
- // CFormDragCommand
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CFormDragCommand constructor
- //----------------------------------------------------------------------------------------
-
- CFormDragCommand::CFormDragCommand(Environment* ev,
- CFormContent* content,
- FW_CFrame* frame) :
- FW_CDragCommand(ev, frame, FW_kCanUndo),
- fFormContent(content)
- {
- SetMenuStringsFromResource(ev, kFormUndoStrings, kUndoDragTextMsg, kRedoDragTextMsg);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CFormDragCommand destructor
- //----------------------------------------------------------------------------------------
-
- CFormDragCommand::~CFormDragCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CFormDragCommand::SaveUndoState
- //----------------------------------------------------------------------------------------
-
- void CFormDragCommand::SaveUndoState(Environment *ev)
- {
- fSavedTextData = fFormContent->GetTextData();
- }
-
- //----------------------------------------------------------------------------------------
- // CFormDragCommand::UndoIt
- //----------------------------------------------------------------------------------------
-
- void CFormDragCommand::UndoIt(Environment* ev)
- {
- fFormContent->SetTextData(ev, fSavedTextData);
- }
-
- //----------------------------------------------------------------------------------------
- // CFormDragCommand::RedoIt
- //----------------------------------------------------------------------------------------
-
- void CFormDragCommand::RedoIt(Environment* ev)
- {
- fFormContent->ClearTextData(ev);
- }
-
- //========================================================================================
- // CFormDropCommand
- //========================================================================================
-
- //----------------------------------------------------------------------------------------
- // CFormDropCommand constructor
- //----------------------------------------------------------------------------------------
-
- CFormDropCommand::CFormDropCommand(Environment *ev,
- CFormContent* content,
- FW_CFrame* frame,
- ODDragItemIterator* dropInfo,
- ODFacet* odFacet,
- const FW_CPoint& dropPoint) :
- FW_CDropCommand(ev, frame, dropInfo, odFacet, dropPoint, FW_kCanUndo),
- fFormContent(content)
- {
- SetMenuStringsFromResource(ev, kFormUndoStrings, kUndoDropTextMsg, kRedoDropTextMsg);
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // CFormDropCommand destructor
- //----------------------------------------------------------------------------------------
-
- CFormDropCommand::~CFormDropCommand()
- {
- }
-
- //----------------------------------------------------------------------------------------
- // CFormDropCommand::SaveUndoState
- //----------------------------------------------------------------------------------------
-
- void CFormDropCommand::SaveUndoState(Environment *ev)
- {
- fSavedTextData = fFormContent->GetTextData();
- }
-
- //----------------------------------------------------------------------------------------
- // CFormDropCommand::UndoIt
- //----------------------------------------------------------------------------------------
-
- void CFormDropCommand::UndoIt(Environment* ev)
- {
- this->SwapSelection(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CFormDropCommand::RedoIt
- //----------------------------------------------------------------------------------------
-
- void CFormDropCommand::RedoIt(Environment* ev)
- {
- this->SwapSelection(ev);
- }
-
- //----------------------------------------------------------------------------------------
- // CFormDropCommand::SwapSelection
- //----------------------------------------------------------------------------------------
-
- void CFormDropCommand::SwapSelection(Environment* ev)
- {
- FW_CString255 textData = fFormContent->GetTextData();
- fFormContent->SetTextData(ev, fSavedTextData);
- fSavedTextData = textData;
- }
-
-